<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>录入名单</title>
<script type="text/javascript">
//定义一个取值的小函数
	function $(id){
		return document.getElementById(id);
	}
	//绑定在表单的事件
	function checkform(){
			//用户名不为空
		   if($('name_1').value=='') {
			   var cu ='<font color="red">用户名不能为空</font>';
			    $('cu').innerHTML=cu ;
				return false;
		   }
			//用户名字符不能多余32个
		   if($('name_1').length>='32') {
			   var cu ='<font color="red">字符不能超过32个</font>';
			    $('cu').innerHTML=cu ;
				return false;
		   }		   
			//标题字符个数控制
		   if($('title').length>='64') {
			   var cu1 ='<font color="red">字符串长度不能超过64个</font>';
			    $('cu1').innerHTML=cu1 ;
				return false;
		   }
		   //Email格式控制
		  	 if($('email').value=='') {
			   var cu2='<font color="red">用户名不能为空</font>';
			    $('cu2').innerHTML=cu2 ;
				return false;
		   } else{
			     var str=$('email').value;
				var reg=/^[a-z0-9A-Z_]+@[a-z0-9A-Z]+(\.[0-9a-zA-Z]+)+$/gi;
				if(!reg.test(str)){
				   var cu2='<font color="red">EMAIL格式不对</font>';
					$('cu2').innerHTML=cu2 ;
					return false;						
					}
			 }
			//生日格式YYYY-MM-DD
		  	 if($('birthday').value=='') {
			   var cu3='<font color="red">生日不为空</font>';
			    $('cu3').innerHTML=cu3 ;
				return false;
		   } else{
			     var str=$('birthday').value;
				//var reg=/^1[0-9]{3}-[0-9]{2}-[0-9]{2}$/gi;
				var reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/gi;
				if(!reg.test(str)){
				   var cu3='<font color="red">生日日期和格式不正确</font>';
					$('cu3').innerHTML=cu3 ;
					return false;						
					}
			 }			
		   
	}
	

</script>
</head>
<body>
<table width="100%" height="300">
  <tr>
    <td align="center">
    <form method="post" id="form_1" onsubmit="return checkform();"  action="php_cgi4.php">
    	<table  height="300">
          <tr>
            <td align="center">Name</td>
            <td width="50" align="left"><input id="name_1" name="name_1" type="text" value="Name" /></td>
            <td width="150" align="left"><span id="cu"></span></td>
          </tr>
          <tr>
            <td align="center">Title</td>
            <td width="50" align="left"><input id="title" name="title" type="text" value="Title"/></td>
            <td width="150" align="left"><span id="cu1"></span></td>
          </tr>
          <tr>
            <td align="center">Body</td>
            <td width="50" align="left"><textarea id="body_1" name="body_1" cols="25" rows="20">Body内容</textarea></td>
            <td width="150" align="left">&nbsp;</td>
          </tr> 
          <tr>
            <td align="center">Email</td>
            <td width="50" align="left"><input id="email" name="email" type="text" value="example@xxx.com" /></td>
            <td width="150" align="left"><span id="cu2"></span></td>
          </tr>
          <tr>
            <td align="center">Birthday</td>
            <td width="50" align="left"><input id="birthday" name="birthday" type="text" value="YYYY-MM-DD"/></td>
            <td width="150" align="left"><span id="cu3"></span></td>
          </tr>          
          <tr>
            <td align="center">&nbsp;</td>
            <td width="50" align="left"><input type="submit" value="提交"/></td>
            <td width="150" align="left">&nbsp;</td>
          </tr>         
        </table>
    </form>
    </td>
  </tr>
</table>
<table width="100%" height="200">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>
